﻿' LibWowArmory
' by Ronald M. Clifford (roncli@roncli.com)
'
' This source code is released under the GNU Library General Public License (LGPL) Version 2.1.

Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Web
Imports System.Xml.Serialization

Namespace roncliProductions.LibWowArmory

    ''' <summary>
    ''' A class that caches additional data for the dungons and bosses available on the Armory
    ''' </summary>
    ''' <remarks>This class is largely used for internal purposes</remarks>
    Public Class DungeonStrings
        Inherits WowArmoryData

        Private dssPage As New DungeonStringsSchema.page

        ''' <summary>
        ''' Returns a list of available dungeons
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Dungeons() As List(Of Dungeon)
            Get
                If dssPage Is Nothing Then
                    Return New List(Of Dungeon)
                End If
                Return (From d In dssPage.dungeons.SelectMany(Function(d) d.dungeon) _
                        Select New Dungeon(d.id, d.key, d.name, CType(d.release, ReleaseType), _
                                           (From b In d.boss Select New Boss(b.id, b.name)).ToList())).ToList()
            End Get
        End Property

        ''' <summary>
        ''' The URL of the dungeon and boss data
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overrides ReadOnly Property URL() As String
            Get
                Return "http://www.wowarmory.com/data/dungeonStrings.xml"
            End Get
        End Property

        ''' <summary>
        ''' Indicates to the inherited class that this request does not require login
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overrides ReadOnly Property RequiresLogin() As Boolean
            Get
                Return False
            End Get
        End Property

        ''' <summary>
        ''' Constructor that retrieves the dungeon and boss data from either the armory or the local cache
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
            If Cache.Cache("LibWowArmory.DungeonStrings") Is Nothing Then
                MyBase.Retrieve()

                Dim xsSerializer As New XmlSerializer(dssPage.GetType())

                Dim srXML As New StringReader(MyBase.strData)

                dssPage = CType(xsSerializer.Deserialize(srXML), DungeonStringsSchema.page)

                Cache.Cache.Insert("LibWowArmory.DungeonStrings", dssPage, Nothing, Date.UtcNow.AddDays(1), Nothing, Caching.CacheItemPriority.NotRemovable, Nothing)
            Else
                dssPage = CType(Cache.Cache("LibWowArmory.DungeonStrings"), DungeonStringsSchema.page)
            End If
        End Sub

        ''' <summary>
        ''' A class that encapsulates a single dungeon returned from the Armory
        ''' </summary>
        ''' <remarks></remarks>
        Public Class Dungeon

            Private intID As Integer
            Private strKey As String
            Private strName As String
            Private rRelease As ReleaseType
            Private bBoss As List(Of Boss)

            ''' <summary>
            ''' The dungeon's identification number
            ''' </summary>
            ''' <value></value>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Property ID() As Integer
                Get
                    Return intID
                End Get
                Set(ByVal value As Integer)
                    intID = value
                End Set
            End Property

            ''' <summary>
            ''' The dungeon's key, used to differentiate between dungeons with the same ID
            ''' </summary>
            ''' <value></value>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Property Key() As String
                Get
                    Return strKey
                End Get
                Set(ByVal value As String)
                    strKey = value
                End Set
            End Property

            ''' <summary>
            ''' The name of the dungeon
            ''' </summary>
            ''' <value></value>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Property Name() As String
                Get
                    Return strName
                End Get
                Set(ByVal value As String)
                    strName = value
                End Set
            End Property

            ''' <summary>
            ''' The release of World of Warcraft the dungeon was introduced in
            ''' </summary>
            ''' <value></value>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Property Release() As ReleaseType
                Get
                    Return rRelease
                End Get
                Set(ByVal value As ReleaseType)
                    rRelease = value
                End Set
            End Property

            ''' <summary>
            ''' A list of bosses contained within this dungeon
            ''' </summary>
            ''' <value></value>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Property Bosses() As List(Of Boss)
                Get
                    Return bBoss
                End Get
                Set(ByVal value As List(Of Boss))
                    bBoss = value
                End Set
            End Property

            ''' <summary>
            ''' Constructor to create a new dungeon object
            ''' </summary>
            ''' <param name="intID"></param>
            ''' <param name="strKey"></param>
            ''' <param name="strName"></param>
            ''' <param name="rRelease"></param>
            ''' <remarks></remarks>
            Public Sub New(ByVal intID As Integer, ByVal strKey As String, ByVal strName As String, ByVal rRelease As ReleaseType, ByVal bBoss As List(Of Boss))
                Me.intID = intID
                Me.strKey = strKey
                Me.strName = strName
                Me.rRelease = rRelease
                Me.bBoss = bBoss
            End Sub

        End Class

        ''' <summary>
        ''' A class that encapsulates a single boss contained within a dungon from the Armory
        ''' </summary>
        ''' <remarks></remarks>
        Public Class Boss

            Private intID As Integer
            Private strName As String

            ''' <summary>
            ''' The identification number of the boss
            ''' </summary>
            ''' <value></value>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Property ID() As Integer
                Get
                    Return intID
                End Get
                Set(ByVal value As Integer)
                    intID = value
                End Set
            End Property

            ''' <summary>
            ''' The name of the boss
            ''' </summary>
            ''' <value></value>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Property Name() As String
                Get
                    Return strName
                End Get
                Set(ByVal value As String)
                    strName = value
                End Set
            End Property

            ''' <summary>
            ''' Constructor to create a new boss object
            ''' </summary>
            ''' <param name="intID"></param>
            ''' <param name="strName"></param>
            ''' <remarks></remarks>
            Public Sub New(ByVal intID As Integer, ByVal strName As String)
                Me.intID = intID
                Me.strName = strName
            End Sub

        End Class

    End Class

End Namespace